package qjc.j_回溯;

import java.util.ArrayList;
import java.util.List;

public class j1_全排列 {
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> res = new ArrayList<List<Integer>>();
        List<Integer> output = new ArrayList<>();
        backtrack(nums,output,res);
        return res;
    }

    private void backtrack(int[] nums, List<Integer> output, List<List<Integer>> res) {
        if (output.size() == nums.length) {
            res.add(new ArrayList<>(output));
        }
        for (int j = 0; j < nums.length; j++) {
            if(!output.contains(nums[j])){
                output.add(nums[j]);
                backtrack(nums,output,res);
                output.remove(output.size()-1);
            }
        }
    }
}
